package com.homework.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class SpringContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext sc = sce.getServletContext();
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        sc.setAttribute("ac",ac);
        System.out.println("IOC容器创建成功。。");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
